package com.shengyin.ec.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.shengyin.ec.model.entity.Users;
import com.shengyin.ec.service.permission.AccountService;

public class UserService implements UserDetailsService {

	@Autowired
	AccountService accoutnService;
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		User user=new User();
		
		Users usr=accoutnService.getUsersByUsername(username);
		if(usr!=null){
			user.setUsername("lining");
			user.setPassword("123456");
			user.setAuthoritiesByString((String[]) usr.getRolenames());
		}
		return user;
	}

}
